<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="box-card" style="background-color: #87DE75; border-color: #87DE75">
          <div class="grid-content">
            <div class="cont-box">
              <span style="float: left">患者总数</span>
              <br>
              <div style="float: left; font-size: 28px; font-weight: bold;margin-top: 30px">
                <CountTo :endVal='initData.patientTotal'></CountTo>
                （人）
              </div>
            </div>
            <div class="icon-box">
              <i class="el-icon-s-custom" style="margin: 0 auto"></i>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" style="background-color: #93b7e3;border-color: #93b7e3">
          <div class="grid-content">
            <div class="cont-box">
              <span style="float: left">报告总数</span>
              <br>
              <div style="float: left; font-size: 28px; font-weight: bold;margin-top: 30px">
                <CountTo :endVal='initData.reportTotal'></CountTo>
                （份）
              </div>
            </div>
            <div class="icon-box">
              <i class="el-icon-s-release" style="margin: 0 auto"></i>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" style="background-color: #e6a23c;;border-color: #e6a23c">
          <div class="grid-content">
            <div class="cont-box">
              <span style="float: left">学校总数</span>
              <br>
              <div style="float: left; font-size: 28px; font-weight: bold;margin-top: 30px">
                <CountTo :endVal='initData.schoolTotal'></CountTo>
                （间）
              </div>
            </div>
            <div class="icon-box">
              <i class="el-icon-platform-eleme" style="margin: 0 auto"></i>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" style="background-color: #f56c6c;;border-color: #f56c6c">
          <div class="grid-content">
            <div class="cont-box">
              <span style="float: left">医院总数</span>
              <br>
              <div style="float: left; font-size: 28px; font-weight: bold;margin-top: 30px">
                <CountTo :endVal='initData.hospitalTotal'></CountTo>
                （所）
              </div>
            </div>
            <div class="icon-box">
              <i class="el-icon-s-help" style="margin: 0 auto"></i>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card class="box-card-middle">
          <div slot="header" class="clearfix">
            <span>报告年度增长曲线</span>
          </div>
          <div id="line-chart" style="height: 442px;"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import {getHome} from "@/api";

export default {
  name: "index",
  components: {
    CountTo
  },
  data() {
    return {
      initData: {}
    }
  },
  async mounted() {
    this.initData = await this.getInitData()
    this.drawLine()
  },
  methods: {
    getInitData() {
      return new Promise((async (resolve) => {
        let res = await getHome();
        resolve(res.data)
      }))

    },
    drawLine() {
      let data = this.initData.yearCount.data
      let chart = this.$echarts.init(document.getElementById('line-chart'),)
      chart.setOption({
        xAxis: {
          type: 'category',
          data: [
            "1月",
            "2月",
            "3月",
            "4月",
            "5月",
            "6月",
            "7月",
            "8月",
            "9月",
            "10月",
            "11月",
            "12月",
          ]
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: data,
            type: 'line'
          }
        ]
      })
    },
  }
}
</script>

<style scoped>
.el-row {
  margin-bottom: 10px;

}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 5px;
  padding: 0 5px !important;
}


.box-card {
  height: 174px;
  text-align: left;
  color: white;
  border-radius: 10px;
}


.grid-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  border-radius: 4px;
  height: 154px;
}

.cont-box {
  flex: 5;
  height: 154px;
  margin-top: 40px;
  margin-left: 10px;
  font-size: 20px;


}

.icon-box {
  flex: 2;
  font-size: 64px;
  /*height: 154px;*/


}


/deep/ .box-card .el-card__header {
  padding: 5px 15px;
}


.box-card-middle, .box-card-bottom {
  height: 500px;
  text-align: left;
}


</style>